<template>
  <div class="ArticleBlog">
    <!--图片标题-->
    <div class="pattern-center single-center">
      <div class="pattern-attachment-img">
        <el-image fit="cover" lazy :src="articleInfo.titlePicture">
          <template #error>
            <div class="image-slot">
              <el-image
                :src="randomArrayIndex(store.state.defaultErrorImageUrl)"
                fit="cover"
              ></el-image>
            </div>
          </template>
        </el-image>
      </div>
      <transition-group
        enter-active-class="animate__animated animate__zoomIn"
        leave-active-class="animate__animated animate__backOutDown"
      >
      </transition-group>
      <transition
        enter-active-class="animate__animated animate__backInDown"
        leave-active-class="animate__animated animate__backOutDown"
      >
        <div class="single-header">
          <h1 class="entry-title">家园卫士！</h1>
        </div>
      </transition>
    </div>
    <div id="content" class="site-content">
      <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">
          <div class="entry-content">
            <!--内容-->
            <MdEditor :mdProps="mdProps"></MdEditor>
            <!--打赏-->
            <div class="single-reward">
              <div class="reward-open"
                >赏
                <div class="reward-main">
                  <ul class="reward-row">
                    <li class="alipay-code">
                      <img
                        src="https://cdn.jsdelivr.net/gh/moezx/cdn@3.3.3/img/other/AliPayQR.jpg"
                      />
                    </li>
                    <li class="wechat-code">
                      <img
                        src="https://cdn.jsdelivr.net/gh/moezx/cdn@3.3.3/img/other/WeChanQR.png"
                      />
                    </li>
                  </ul>
                </div>
              </div>
            </div>
          </div>
          <!-- 翻页导航-->
          <div class="post-nav">
            <div @click="goRecommendArticle(recommendArticleInfo.pre.id)">
              <div class="left-pre">
                <el-image
                  :z-index="-500"
                  fit="cover"
                  :src="recommendArticleInfo.pre.titlePicture"
                >
                  <template #error>
                    <div class="image-slot">
                      <el-image
                        :src="
                          randomArrayIndex(store.state.defaultErrorImageUrl)
                        "
                        fit="cover"
                      ></el-image>
                    </div>
                  </template>
                </el-image>
                <div class="blog-label">
                  <span class="label">PREVIOUS POST</span>
                  <div class="info">
                    <h3>{{ recommendArticleInfo.pre.title }}</h3>
                  </div>
                </div>
              </div>
            </div>
            <div @click="goRecommendArticle(recommendArticleInfo.next.id)">
              <div class="right-next">
                <el-image
                  :z-index="-500"
                  fit="cover"
                  :src="recommendArticleInfo.next.titlePicture"
                >
                  <template #error>
                    <div class="image-slot">
                      <el-image
                        :src="
                          randomArrayIndex(store.state.defaultErrorImageUrl)
                        "
                        fit="cover"
                      ></el-image>
                    </div>
                  </template>
                </el-image>
                <div class="blog-label">
                  <span class="label">Previous Post</span>
                  <div class="info"
                    ><h3>{{ recommendArticleInfo.next.title }}</h3></div
                  >
                </div>
              </div>
            </div>
          </div>

          <!-- 个人信息 -->
          <section class="author-profile">
            <p
              ><i class="iconfont icon-write"></i
              >探索真理之门——真理是实践的女儿</p
            >
          </section>
        </main>
      </div>
    </div>
  </div>
  <!--分享区,版权区-->
  <div
    class="three_consecutive_operations"
    @click="headerTopDown('#comment-anchor')"
  >
  </div>
</template>

<script setup>
  import { onBeforeMount, reactive, ref, onMounted } from 'vue'

  import MdEditor from '@/components/markdown/MdEditor'
  import { randomArrayIndex } from '@/utils/randomArrayElemt.js'

  import { useStore } from 'vuex'

  import { useRouter } from 'vue-router'
  import { getRecommend } from '@/api/article/article.js'
  import { getReport } from '@/api/custom/healthReport.js'

  import { headerTopDown } from '@/utils/webutils'

  const store = new useStore()
  const router = new useRouter()

  //内容为空不展示
  const isEmpty = ref(false)

  //是否显示文章信息
  const isShowTitle = ref(false)

  //文章评论显示
  // const isShowArticleComment = ref(false)

  // 文章信息
  const articleInfo = reactive({
    titlePicture: '',
    title: '',
    views: '',
    createTime: '',
    user: {
      avatar: '',
      name: ''
    }
  })

  //推荐文章信息
  const recommendArticleInfo = reactive({
    pre: {},
    next: {}
  })
  // markdown配置
  const mdProps = reactive({
    context: '',
    theme: 'light',
    previewOnly: true,
    defaultShowToc: true,
    tocNavPositionRight: true,
    defaultFullscreen: true,
    includeLevel: [1, 5],
    editorId: 'articleId',
    style: {
      background: 'rgb(255 255 255 / 0%) !important',
      color: 'var(--font-color)'
    }
  })

  /**
   * 控制评论显示
   * @param bool
   */
  // const showArticleCommentFun = (bool) => {
  //   isShowArticleComment.value = bool
  // }

  /**
   * 获取详细信息
   */
  const getArticleDetails = () => {
    isEmpty.value = false
    getReport({})
      .then((res) => {
        if (_.isEmpty(res.data)) {
          isEmpty.value = true
          return
        }
        mdProps.context = res.data
      })
      .catch(() => {
        isEmpty.value = true
        isShowTitle.value = true
        document.title = '加载失败啦~~~~'
      })
  }

  /**
   * 获取推荐文章
   * @param id
   */
  const getRecommendList = () => {
    getRecommend({})
      .then((res) => {
        recommendArticleInfo.next = res.data.next
        recommendArticleInfo.pre = res.data.pre
      })
      .catch(() => {})
  }

  /**
   * 推荐文章
   * @param id
   */
  const goRecommendArticle = (id) => {
    router.push(`/article/${id}`)
  }

  onBeforeMount(() => {
    getArticleDetails()
  })

  onMounted(() => {
    getRecommendList()
  })
</script>

<style lang="less" scoped>
  .post-nav {
    margin: 25px 0;
    height: 150px;
    display: flex;
    background-color: #000000;
    justify-content: space-between;
    border-radius: 10px 10px 0 0;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);

    :deep(.el-image) img {
      opacity: 0.4;
      background-size: cover;
      -webkit-transition: opacity 0.15s ease-out;
      -moz-transition: opacity 0.15s ease-out;
      transition: opacity 0.15s ease-out;
      border-radius: 10px 10px 0 0;
    }

    .left-pre:hover > :deep(.el-image) img,
    .right-next:hover > :deep(.el-image) img {
      opacity: 0.7;
    }

    div {
      overflow: hidden;
      flex: 1;
    }

    .left-pre {
      position: relative;

      .blog-label {
        position: absolute;
        top: 50px;
        left: 35px;
        text-align: left;
      }
    }

    .right-next {
      position: relative;

      .blog-label {
        position: absolute;
        top: 50px;
        right: 60px;
        text-align: right;
      }
    }

    .blog-label {
      span,
      .info h3 {
        font-size: 14px;
        font-weight: 400;
        line-height: 30px;
        color: #fff;
        text-transform: uppercase;
        color: rgba(255, 255, 255, 0.7);
      }
    }

    span,
    h3 {
      overflow: hidden !important;
      text-overflow: ellipsis !important;
      display: -webkit-box !important;
      -webkit-box-orient: vertical !important;
      word-break: break-all !important; /*追加这一行代码*/
    }
  }

  .comment-form {
    .comment-user-avatar {
      display: flex;
      align-items: center;
      justify-content: center;

      .el-avatar {
        display: inline-block;
      }

      i {
        position: relative;
        right: 15px;
        bottom: 3px;
        color: #3cb45e;
        border-radius: 40%;
      }
    }

    .user-comment-Info {
      display: flex;
      flex-direction: column;

      .el-form-item--default .el-form-item__label {
        line-height: 42px;
      }
    }
  }

  :deep(.el-form-item__content) {
    margin-left: 0 !important;
  }

  i {
    font-size: 20px;
  }

  .post-tags {
    i {
      font-size: 16px;
    }
  }

  .pattern-attachment-img {
    .el-image {
      width: 100%;
      height: 100%;
    }

    .image-slot {
      width: 100%;
      height: 100%;
    }
  }

  .single-center {
    .single-header {
      max-width: 860px;
      padding: 0 10px;
      margin-left: auto;
      margin-right: auto;
      margin-bottom: 60px;
      text-align: left;
      top: auto;
      bottom: 0;
      position: absolute;
      left: 0;
      right: 0;
      color: #fff;
      text-shadow: 2px 2px 10px #000;
      z-index: 1;

      .entry-census {
        .name {
          margin-left: 0.5rem;
        }

        .bull {
          margin: 0 0.5rem;
        }
      }
    }
  }

  .comment-textarea {
    :deep(.el-form-item__error) {
      top: 80%;
    }
  }

  .single-center .single-header {
    margin-bottom: 50px;
  }

  @media (max-width: 860px) {
    .single-center {
      .single-header {
        margin-bottom: 0;

        :deep(.el-col-22) {
          padding: 0 0 0 20px;
        }
      }
    }

    :deep(.notice) {
      font-size: 16px;
    }

    .post-nav {
      height: 100px;

      .left-pre .blog-label {
        top: 10px;
        left: 10px;
      }

      .right-next .blog-label {
        top: 10px;
        right: 10px;
      }
    }

    .single-center .entry-census {
      margin-bottom: 50px;

      p span {
        display: inline-block;
      }
    }
  }

  .three_consecutive_operations {
    position: fixed;
    display: flex;
    justify-content: center;
    align-items: center;
    bottom: 10vh;
    left: 35px;
    z-index: 100;

    .operations {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 55px;
      height: 55px;
      background-color: var(--global-bg);
      box-shadow: 1px 1px 10px rgba(0, 0, 0, 0.2);
      transition: all 0.6s;
      cursor: pointer;
      border-radius: 50%;
      flex-direction: column;
      color: var(--font-color);

      div {
        margin: 2px 0;
      }
    }
  }

  .author-profile {
    .el-avatar--default {
      --el-avatar-size: px;
    }
  }

  .comment-user-avatar {
    .el-avatar--default {
      --el-avatar-size: 50px;
    }
  }

  .author {
    a {
      text-decoration: none;
    }
  }

  :deep(.el-input__inner) {
    border: none;
    background: var(--tab-botton-bg);
    color: var(--font-color);
    margin-bottom: 0;
  }

  :deep(.el-input__inner:focus) {
    color: var(--text-accent);
    box-shadow: 0 0 0 1px var(--text-accent) inset;
    background-color: var(--input-bg);
  }

  :deep(.el-input-group__prepend) {
    border: none;
    background: var(--tab-botton-bg);
    color: var(--font-color);
  }

  :deep(.el-textarea__inner:focus) {
    color: var(--text-accent);
    box-shadow: 0 0 0 1px var(--text-accent) inset;
    background-color: var(--input-bg);
  }

  :deep(.el-textarea__inner) {
    background-color: var(--tab-botton-bg);
  }

  .submit-comment {
    display: flex;
    justify-content: center;

    button {
      margin: 10px 30px;
    }
  }
</style>
